/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ControlEscolar.Services;


import com.ControlEscolar.Beans.Major;
import com.ControlEscolar.DAOs.DAOException;
import com.ControlEscolar.DAOs.MajorDAO;
import com.ControlEscolar.Exceptions.AlreadyExistExp;
import com.ControlEscolar.Exceptions.DeleteExp;
import com.ControlEscolar.Exceptions.ServiceExp;
import com.ControlEscolar.Validations.ValidationsMajor;
import java.util.ArrayList;

/**
 *
 * @author Rodna Marrufo
 */
public class MajorService {
    MajorDAO majorDAO = new MajorDAO();

    ValidationsMajor validationMajor=new ValidationsMajor();

    public void createMajor(Major major) throws AlreadyExistExp, ServiceExp{
       try{
        if(validationMajor.isExistMajor(major.getID_Major())){
            throw new AlreadyExistExp("YA EXISTE ESE DATO");
        }
        else
            majorDAO.add(major);}
       catch(DAOException e){
            throw new ServiceExp();
        }
    }

    public void updateMajor(Major major) throws ServiceExp {
       try{
        majorDAO.update(major);}
       catch(DAOException e){
            throw new ServiceExp();
        }
    }
    
    public void deleteMajor(Major major) throws ServiceExp, DeleteExp {
      try{
        if(validationMajor.isMajorInCurriculum(major.getID_Major()))
            throw new DeleteExp("CARRERA ASIGNADA A CURRICULUM");
        else
            majorDAO.delete(major.getID_Major());
      }
      catch(DAOException e){
            throw new ServiceExp();
        }
    }

     public ArrayList<Major> getMajorList() throws ServiceExp {
      try{
        return majorDAO.query();}
      catch(DAOException e){
            throw new ServiceExp();
        }
    }

   }

   


